package game{
	import flash.display.Bitmap;
	import flash.utils.getTimer;
	public class SpaceShip extends GameObject{
		[Embed(source="../../res/spaceship2.png")]
		public var SpaceShipImage:Class;
		
		[Embed(source="../../res/spaceship-acce.png")]
		public var SpaceShipAcceImage:Class;
		
		private var spaceShipImage:Bitmap;
		private var spaceShipAcceImage:Bitmap;
		
		protected var isAccelerating:Boolean;
		
		public function SpaceShip(game:Game){
			super(game);
			spaceShipImage = new SpaceShipImage();
			spaceShipAcceImage = new SpaceShipAcceImage();
			
			image = spaceShipImage.bitmapData;
			
			graphics.beginBitmapFill(image);
			graphics.endFill();
		}
		
		override protected function prepareCalc(time:Number):void{
			if(isAccelerating){
				
			}else{
				if(Math.abs(speedX) <= 0.1 || (speedX >= 0 && acceX >= 0) || (speedX <= 0 && acceX <= 0)){
					speedX = 0;
					acceX = 0;
				}
				
				if(Math.abs(speedY) <= 0.1 || (speedY >= 0 && acceY >= 0) || (speedY <= 0 && acceY <= 0)){
					speedY = 0;
					acceY = 0;	
				}
				
			}
			
//			trace(acceX , speedX , acceY, speedY);
		}
		
		private var on:Boolean = false;
		override protected function prepareDraw():void{
			if(isAccelerating){
//				if(int((getTimer() % 50) / 25) == 0){
				if(on){
//					this.image = spaceShipAcceImage.bitmapData;
				}else{
//					this.image = spaceShipImage.bitmapData;					
				}
				
				on = !on;
			}
		}
		
		public function powerUp():void{
			if(!isAccelerating){
				var radian:Number = angleToRadian(rotateAngle);
				acceX = Math.sin(radian);
				acceY = - Math.cos(radian);
//				trace("加速 X方向加速度 ",acceX," Y方向加速度",acceY);
			}
			
			isAccelerating = true;
		}
		
		public function powerDown():void{
			if(isAccelerating){
				isAccelerating = false;
				this.image = spaceShipImage.bitmapData;
				acceX = - (speedX / Math.abs(speedX)) / 50;
				acceY = - (speedY / Math.abs(speedY)) / 50;
				
//				trace("减速 X方向减速度 ",acceX," Y方向减速度",acceY);				
			}
		}
		
		public function fire():void{
			
		}
	}
}